package com.ugoodtech.mdcc.core.repository;

import com.ugoodtech.mdcc.core.domain.StationColorReport;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StationColorReportRepository extends PagingAndSortingRepository<StationColorReport, Long>
        , QueryDslPredicateExecutor<StationColorReport> {

    @Query("from StationColorReport where report_id=:report_id and question_id=:question_id and deleted=false and enabled=true")
    StationColorReport selectReport(@Param("report_id") Long report_id, @Param("question_id") Long question_id);

    @Query("from StationColorReport where report_id in :report_id and question_id=:question_id "
        + "and deleted=false and enabled=true")
    List<StationColorReport> selectReport(@Param("report_id") List<Long> report_id,
        @Param("question_id") Long question_id);

    @Query("from StationColorReport where report_id in :report_id and question_id in :question_id "
        + "and deleted=false and enabled=true")
    List<StationColorReport> selectReport(@Param("report_id") List<Long> report_id,
        @Param("question_id") List<Long> question_id);

    @Query("from StationColorReport where report_id in :report_id and question_id in :question_id "
        + "and deleted=false and enabled=true")
    List<StationColorReport> selectReportQuestion(@Param("report_id") List<Long> report_id,
        @Param("question_id") List<Long> question_id);

    @Query("from StationColorReport where report_id=:report_id and deleted=false and enabled=true")
    List<StationColorReport> selectAnswer(@Param("report_id") Long report_id);

    @Query(value = "select count(*) from station_color_report where answer_other_id=:answer_other_id and answer_id=222 and id in(:colorReportIds)", nativeQuery = true)
    Object countOtherBrand(@Param("answer_other_id") String answer_other_id, @Param("colorReportIds") Long[] colorReportIds);

    @Query(value = "select b.answer_other_id from station_report a,station_color_report b where a.station_id=:stationId and a.id=b.report_id and a.category='techcolor_report' and b.question_id=14", nativeQuery = true)
    Object getPaintCompany(@Param("stationId") Long stationId);


}
